<?php include 'header.php';?>

<?php //company.php

if (isset($_POST['name'])) $name=$_POST['name'];
else $name="not data";

$result = mysql_query("SELECT company_id FROM company WHERE company_name='$name'");   
$company_no= mysql_result($result,0);

echo<<<_END

<html>
	<head>
		<title>Form test</title>
	</head>
	<body>
	<form method="post" action="company.php" />
		Insert company name!
		<input type="text" name="name" />
		<input type="submit" value="search" />
	</form>
	this is : $name<br/>
	</body>
</html>
_END;

$result = mysql_query("SELECT B.company_name,B.type, D.model_name, D.model_type FROM company AS B LEFT OUTER JOIN 
(SELECT * FROM model AS A, company_to_model AS C WHERE A.model_name = C.model_nam) as D on B.company_id = D.company_id WHERE B.company_id = $company_no");
if (!$result) {
    die("Query to show fields from table failed");
}

$fields_num = mysql_num_fields($result);

echo "<h1>Table: {$name}</h1>";
echo "<table border='1'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
    $field = mysql_fetch_field($result);
    echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result))
{
    echo "<tr>";
    // $row is array... foreach( .. ) puts every element
    // of $row to $cell variable
    foreach($row as $cell)
        echo "<td>$cell</td>";

    echo "</tr>\n";
}

$result = mysql_query("SELECT * FROM patent WHERE company_id = $company_no");
if (!$result) {
    die("Query to show fields from table failed");
}

$fields_num = mysql_num_fields($result);

echo "<table border='1'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
    $field = mysql_fetch_field($result);
    echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result))
{
    echo "<tr>";
    // $row is array... foreach( .. ) puts every element
    // of $row to $cell variable
    foreach($row as $cell)
        echo "<td>$cell</td>";

    echo "</tr>\n";
}
mysql_free_result($result);
?>
